DEFINITION FOR C MODULE M2Lib ;

FROM SYSTEM IMPORT ADDRESS, STRING ;

VAR (* The following variables are READ ONLY!! *)
  wbStarted : BOOLEAN ;
  _WBMsg    : ADDRESS ; (* Startup message sent to us by workbench,	     *)
  			(* Do not reply to it, as the DICE exit code will    *)
  			(* do this at the correct time.			     *)
  			(* WBMsg is only valid if wbStarted = TRUE	     *)
  			(* There is a copy of this variable in WorkBench.def *)
  			(* which is properly typed: VAR WBMsg : WBStartupPtr *)

(* following are only valid if wbStarted = FALSE (CLI startup) *)
  argc : LONGINT ; (* # of cmd line arguments eg [m2c x.mod] = 2 arguments *)
  argv : POINTER TO ARRAY (* 0..argc-1 *) OF STRING ;

PROCEDURE OpenLib( name : STRING ; version : LONGINT ) : ADDRESS ;
(* Like the Exec version but the library is automatically closed at program   *)
(* exit.								      *)

PROCEDURE _ErrorReq( s1,s2 : STRING ) ;
(* Displays an error requester with s1,s2 and then calls StdLib.exit(20)  *)
(* dont pass NIL as either argument pass " " instead.			  *)

PROCEDURE CheckStack( needBytes : LONGINT ) ;
(* Checks that needBytes of space are avaiable on the stack.		 *)
(* calls _ErrorReq if there are not.					 *)
(* Used for manual stack checking. Place calls to this procedure in 	 *)
(* the recursive call paths of your program.			 	 *)
(* If the check fails then this functions mallocs a new stack before the *)
(* _ErrorReq call.							 *)
(* DO NOT use if youre program creates coroutines or Exec tasks		 *)

PROCEDURE CheckStack512 ;
(* Same as CheckStack(512) but faster *)

(* Duplicated from StdLib.def *)

TYPE
  IntProc = PROCEDURE( ) : LONGINT ;

PROCEDURE onbreak( ip : IntProc ) : IntProc ;
PROCEDURE atexit( p : PROC ) ;
PROCEDURE exit( n : LONGINT ) ;

PROCEDURE malloc( size : LONGINT ) : ADDRESS ;
PROCEDURE free( a : ADDRESS ) ;

END M2Lib.
